package aps.module_Core;

//Vanilla Minecraft
import java.util.List;

import net.minecraft.src.CreativeTabs;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.Item;
import net.minecraft.src.ItemStack;
import net.minecraft.src.World;

//forge
import net.minecraft.src.ModLoader;

//APS
import aps.BuildcraftAPS;

public class ItemAPSKit extends Item
{
	static int[] TexIndexes = new int[32];
	static String[] KitNames = new String[32];
	static APSKitItemAction[] action = new APSKitItemAction[32];
	
	public ItemAPSKit(int i) {
		super(i);

        setHasSubtypes(true);
        setMaxDamage(0);
        
        for(int a = 0; a < 32; a++) {TexIndexes[a] = 255;}
        for(int a = 0; a < 32; a++) {KitNames[a] = "";}
        
        this.setCreativeTab(CreativeTabs.tabRedstone);
	}

	public static void registerKit(int Metadata, int IconIndex, String Name)
	{
		TexIndexes[Metadata] = IconIndex;
		KitNames[Metadata] = module_Core.APSKitItem.getItemName() + "." + Metadata;
		ModLoader.addLocalization(module_Core.APSKitItem.getItemName() + "." + Metadata + ".name", Name + " Kit");
	}
	
	public static void registerKit(int Metadata, int IconIndex, String name, APSKitItemAction itemAction)
	{
		action[Metadata] = itemAction;
		registerKit(Metadata, IconIndex, name);
	}
	
	@Override
	public int getIconFromDamage(int i)
	{
		if(i >= 32) return 0;
		return TexIndexes[i];
	}

	@Override
	public String getItemNameIS(ItemStack itemstack)
	{
		if(itemstack.getItemDamage() >= 32) return "";
		return KitNames[itemstack.getItemDamage()];
	}
	
	@Override
	public String getLocalItemName(ItemStack itemstack)
    {
        String s = getItemNameIS(itemstack);
        if (s == null)
            return "";
        else
        	return s;
    }

	@Override
	public String getTextureFile()
	{
		return BuildcraftAPS.imageFilesRoot + "APSItemTexes.png";
	}
	
	public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3List)
    {
        for (int var4 = 0; var4 < 32; ++var4)
        {
        	if (module_Core.APSMetaSubs[var4] != null)
        		par3List.add(new ItemStack(par1, 1, var4));
        }
    }
	
	//public boolean onItemUse(ItemStack itemstack, EntityPlayer player, World world, int posX, int posY, int posZ, int par7, float par8, float par9, float par10)
	public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer player)
	{
		if (action[itemstack.getItemDamage()] != null)
			return action[itemstack.getItemDamage()].Action(itemstack, world, player);
		else 
			return itemstack;
	}
}